package cc.vv.lkimagecomponent2.loaderplugin;

import android.content.Context;

import cc.vv.lkimagecomponent2.LKImage;
import cc.vv.lkimagecomponent2.lib.LoadFactory;
import cc.vv.lklibrary.log.LogOperate;

/**
 * 图片加载插件API.不向外暴露此api.
 *
 * @author dupeng dupeng@vv.cc
 * @date 2018/3/16
 */

public class LoadPlugin {
    private static LoadPlugin instance;

    public static LoadPlugin getInstance() {
        if (instance == null) {
            synchronized (LoadPlugin.class) {
                if (instance == null) {
                    instance = new LoadPlugin();
                }
            }
        }
        return instance;
    }

    /**
     * 加载
     *
     * @param context
     * @return
     */
    public LoadConfig.ConfigBuilder load(Context context) {
        Context context1 = context;
        if (context1 == null) {
            context1 = LKImage.getContext();
        }
        if (context1 == null) {
            LogOperate.e("LKImage load context 为空！使用此库，必须提前调用init()方法,传入applicationContext!");
            throw new NullPointerException("LKImage load() 入参context为空,并且使用此库，必须提前调用init()方法,传入applicationContext!");
        }
        return new LoadConfig.ConfigBuilder(context1);
    }

    /**
     * 参数设置完成后,设置参数类会调用此方法,进行load
     *
     * @param loadConfig
     */
    public void build(LoadConfig loadConfig) {
        LoadFactory.getInstance().getEngine().load(loadConfig);
    }

}

